// by Xeno
//#define __DEBUG__
#define THIS_FILE "x_save_layoutgear.sqf"
#include "x_setup.sqf"

private ["_p", "_prim_pweap_mag", "_prim_pweap_mag_class", "_sec_pweap_mag", "_sec_pweap_mag_class", "_handgun_pweap_mag", "_handgun_pweap_mag_class"];

_p = player;
if (primaryWeapon _p == "") exitWith {systemChat (localize "STR_DOM_MISSIONSTRING_341")};

_magsammofull = magazinesAmmoFull _p;
__TRACE_1("","_magsammofull");

_handgun_pweap = handgunWeapon _p;
_sec_pweap = secondaryWeapon _p;
_prim_pweap = primaryWeapon _p;
_backpack = backpack _p;

_backpackcargo = if (_backpack != "") then {
	backpackCargo (unitBackpack _p);
} else {
	[]
};

GVAR(custom_layout) = [
	((assignedItems _p) - [headgear _p] - [goggles _p]),  //0
	_magsammofull, //1
	_prim_pweap, //2
	primaryWeaponItems _p, //3
	_sec_pweap, //4
	secondaryWeaponItems _p, //5
	_handgun_pweap, //6
	handgunItems _p, //7
	"", //8
	uniform _p, //9
	vest _p, // 10
	_backpack, //11
	goggles _p, //12
	headgear _p, //13
	items _p, //14
	_backpackcargo, // 15
	magazines _p // 16
];

if (!GVAR(with_ranked)) then {
	_side = str GVAR(player_side);
	_pgearl = profileNamespace getVariable QGVAR(dom_gear_l);
	if (isNil "_pgearl") then {
		_pgearl = [
			["WEST",[]],
			["EAST",[]],
			["RESISTANCE",[]],
			["DEFAULT",[]]
		];
	};
	
	switch (_side) do {
		case "WEST": {_pgearl set [0, ["WEST", GVAR(custom_layout)]]};
		case "EAST": {_pgearl set [1, ["EAST", GVAR(custom_layout)]]};
		case "RESISTANCE": {_pgearl set [2, ["RESISTANCE", GVAR(custom_layout)]]};
		default {_pgearl set [3, ["DEFAULT", GVAR(custom_layout)]]};
	};
	
	profileNamespace setVariable [QGVAR(dom_gear_l), _pgearl];
	saveProfileNamespace;
};

__pSetVar [QGVAR(custom_backpack), if (count __pGetVar(GVAR(player_backpack)) > 0) then {
	__pGetVar(GVAR(player_backpack))
} else {
	[]
}];

__TRACE_1("","d_custom_layout");

systemChat (localize "STR_DOM_MISSIONSTRING_342");